<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>
        <ui:composition template="./../Template/generalTemplate.xhtml">
            <ui:define name="content">
                <p:panel id="companyMgt" header="Manage Company" style="height:495px;">
                    <div style="margin-top:30px;margin-left:10px;">
                        <h:form id="form">
                            <p:growl id="msgs" showDetail="true" /> 
                            <p:dataTable id="companies" value="#{deleteCompanyManagedBean.getCompanies()}" var="companyList" paginator="true" rows="5">

                                <p:column headerText="Company Name">
                                    <h:outputText value="#{companyList.name}"/>
                                </p:column>

                                <p:column headerText="Address">
                                    <h:outputText value="#{companyList.address}"/>
                                </p:column>
                                <p:column headerText="Email">
                                    <h:outputText value="#{companyList.email}"/>
                                </p:column>
                                <p:column headerText="Title">
                                    <h:outputText value="#{companyList.contactPersonTitle}"/>
                                </p:column>
                                <p:column headerText="Name">
                                    <h:outputText value="#{companyList.contactPersonName}"/>
                                </p:column>
                                <p:column headerText="Contact">
                                    <h:outputText value="#{companyList.contactNumber}"/>
                                </p:column>
                                <p:column headerText="Type">
                                    <h:outputText value="#{companyList.companyType}"/>
                                </p:column>
                                <p:column headerText="Status">
                                    <h:outputText value="#{companyList.companyStatus}"/>
                                </p:column>



                                <p:column style="width:100px">  
                                    <h:panelGrid columns="2"    styleClass="actions" cellpadding="2">  

                                        <p:commandButton update=":form:display" oncomplete="carDialog.show()" image="ui-icon ui-icon-pencil" title="Edit">  
                                            <f:setPropertyActionListener value="#{companyList}" target="#{deleteCompanyManagedBean.selectedCompany}" />  
                                            <f:setPropertyActionListener value="#{true}" target="#{deleteCompanyManagedBean.editMode}" />  
                                        </p:commandButton>  
                                        <p:commandButton update=":form:display" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="Delete">  
                                            <f:setPropertyActionListener value="#{companyList}" target="#{deleteCompanyManagedBean.selectedCompany}" />  
                                        </p:commandButton>  
                                    </h:panelGrid>  
                                </p:column>  

                            </p:dataTable>  

                            <p:dialog header="Edit Company" widgetVar="carDialog" resizable="false" id="carDlg"  
                                      showEffect="fade" hideEffect="explode" modal="true" width="500">  

                                <h:panelGrid id="display"  columns="2" cellpadding="4" style="margin:0 auto;">  



                                    <h:outputText value="Company Name" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteCompanyManagedBean.selectedCompany.name}" style="font-weight:bold" rendered="#{!deleteCompanyManagedBean.editMode}"/>  
                                        <p:inputText id="name" required="true" requiredMessage="Name cannot be empty" value="#{deleteCompanyManagedBean.selectedCompany.name}" rendered="#{deleteCompanyManagedBean.editMode}"  label="Company Name"/>  
                                        <p:message for="name"/>
                                    </h:panelGroup>  

                                    <h:outputText value="Company Address" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteCompanyManagedBean.selectedCompany.address}" style="font-weight:bold" rendered="#{!deleteCompanyManagedBean.editMode}"/>  
                                        <p:inputText id="address"   requiredMessage="Address cannot be empty" value="#{deleteCompanyManagedBean.selectedCompany.address}" rendered="#{deleteCompanyManagedBean.editMode}" required="true" label="Company Address"/>  
                                        <p:message for="address"/>
                                    </h:panelGroup>  

                                    <h:outputText value="Company Email" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteCompanyManagedBean.selectedCompany.email}" style="font-weight:bold" rendered="#{!deleteCompanyManagedBean.editMode}"/>  
                                        <p:inputText requiredMessage="Email cannot be empty" id="email" value="#{deleteCompanyManagedBean.selectedCompany.email}" rendered="#{deleteCompanyManagedBean.editMode}" required="true" label="Company Email">  
                                            <f:validator validatorId="company.managedbean.validation"/>
                                        </p:inputText>
                                        <p:message for="email"/>
                                    </h:panelGroup>  

                                    <h:outputText value="Contact Person Title" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteCompanyManagedBean.selectedCompany.contactPersonTitle}" style="font-weight:bold" rendered="#{!deleteCompanyManagedBean.editMode}"/>  
                                        <h:selectOneMenu id="title" required="true" requiredMessage="Please select a title" value="#{deleteCompanyManagedBean.selectedCompany.contactPersonTitle}" rendered="#{deleteCompanyManagedBean.editMode}">  
                                            <f:selectItem itemValue="Mr" itemLabel="Mr"/>
                                            <f:selectItem itemValue="Mrs" itemLabel="Mrs"/>
                                            <f:selectItem itemValue="Ms" itemLabel="Ms"/>   
                                        </h:selectOneMenu>  
                                        <p:message  for="title" />
                                    </h:panelGroup>  




                                    <h:outputText value="Contact Person Name" />  
                                    <h:panelGroup> 

                                        <h:outputText value="#{deleteCompanyManagedBean.selectedCompany.contactPersonName}" style="font-weight:bold" rendered="#{!deleteCompanyManagedBean.editMode}"/>  
                                        <p:inputText id="cpname"   requiredMessage="Name cannot be empty" value="#{deleteCompanyManagedBean.selectedCompany.contactPersonName}" rendered="#{deleteCompanyManagedBean.editMode}" required="true" label="Contact Person Name"/>  
                                        <p:message for="cpname"/>
                                    </h:panelGroup>  

                                    <h:outputText value="Contact Number" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteCompanyManagedBean.selectedCompany.contactNumber}" style="font-weight:bold" rendered="#{!deleteCompanyManagedBean.editMode}"/>  
                                        <p:inputText id="cnumber"   requiredMessage="Number cannot be empty" value="#{deleteCompanyManagedBean.selectedCompany.contactNumber}" rendered="#{deleteCompanyManagedBean.editMode}" required="true" label="Contact Number"/>  
                                        <p:message for="cnumber"/>
                                    </h:panelGroup>  

                                    <h:outputText value="Company Type" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteCompanyManagedBean.selectedCompany.companyType}" style="font-weight:bold" rendered="#{!deleteCompanyManagedBean.editMode}"/>  
                                        <h:selectOneMenu id="type" required="true"  value="#{deleteCompanyManagedBean.selectedCompany.companyType}" rendered="#{deleteCompanyManagedBean.editMode}">  
                                            <f:selectItem itemValue="Direct Sales" itemLabel="Direct Sales"/> 

                                            <f:selectItem itemValue="Whole Sales" itemLabel="Whole Sales"/>   
                                        </h:selectOneMenu>  
                                        <p:message  for="type" />
                                    </h:panelGroup>  


                                     


                                    <f:facet name="footer">  
                                        <p:outputPanel rendered="#{deleteCompanyManagedBean.editMode}" layout="block" style="text-align:right">  
                                            <p:commandButton value="Save" update="companies msgs" actionListener="#{deleteCompanyManagedBean.saveChanges}"   
                                                             oncomplete="carDialog.hide()" image="ui-icon ui-icon-check"/>  
                                            <p:commandButton value="Cancel" onclick="carDialog.hide()" type="button" image="ui-icon ui-icon-close"/>  

                                        </p:outputPanel>  
                                    </f:facet>  
                                </h:panelGrid>  

                            </p:dialog>

                            <p:confirmDialog message="Are you sure?" width="200"  
                                             showEffect="explode" hideEffect="explode"  
                                             header="Confirm" severity="alert" widgetVar="confirmation">  

                                <p:commandButton value="Yes" update="companies" actionListener="#{deleteCompanyManagedBean.deleteCompany}" oncomplete="confirmation.hide()">  
                                    <f:attribute name="param1" value="#{deleteCompanyManagedBean.selectedCompany.id}" />
                                </p:commandButton>
                                <p:commandButton value="Not yet" onclick="confirmation.hide()" type="button" />  

                            </p:confirmDialog>  

                        </h:form>  
                    </div>
                </p:panel>
            </ui:define>
        </ui:composition>
    </body>
</html>